<template>
    <Table :data="data" :columns="tbColumns" @on-selection-change="selectChange" :max-height="320">
        <template slot-scope="{ row, index }" slot="action">
            <div class="table-action">
                <Button type="text" @click="handleDelete(row, index)">删除</Button>
            </div>
        </template>
    </Table>
</template>
<script>
export default {
    props: {
        type: {
            type: Number,
            default: 0 // 0 查看 1 多选
        },
        data: {
            type: Array,
            default: () => []
        }
    },
    data () {
        return {
            columns: [
                {
                    type: 'selection',
                    width: 50,
                    align: 'center'
                },
                { title: '序号', type: 'index', align: 'center', width: 80 },
                { title: '班级编号', key: 'classNo', align: 'center' },
                { title: '班级名称', key: 'className', align: 'center' },
                { title: '所属专业', key: 'majorName', align: 'center' },
                { title: '入学学年', key: 'enterYear', align: 'center' },
                { title: '班级人数', key: 'stuNum', align: 'center' },
                { title: '操作', slot: 'action', align: 'center', width: 60 }
            ],
            list: []
        }
    },
    computed: {
        tbColumns () {
            let data = []
            switch (this.type) {
                case 0:
                    data = this.columns.slice(1)
                    break
                case 1:
                    data = this.columns.slice(0, this.columns.length - 1)
                    break
                default:
                    data = this.columns.slice()
            }
            return data
        }
    },
    methods: {
        selectChange (v) {
            this.$emit('on-selection-change', v)
        },
        handleDelete (data, i) {
            this.$emit('delete', data, i)
        }
    }
}
</script>
